Skip to content

Fix wrongly identified circular dependencies#2113

Closed
harrysarson wants to merge 4 commits intoapache:masterfrom
harrysarson:harry/loader-bugs
Closed

Fix wrongly identified circular dependencies#2113
harrysarson wants to merge 4 commits intoapache:masterfrom
harrysarson:harry/loader-bugs

Conversation

@harrysarson
Copy link
Copy Markdown
Contributor

Fixes #2037

This commit adds an additional level of nesting to the override-self
buildstream test project by a new subproject and moving the
self-junction into the subproject.

Both the `link.bst` and the `nested-link.bst` elements point to the
subproject's `target.bst` element but `nested-link.bst` does so via the
self-junction, hence the "nesting".

Running `bst show --deps none nested-link.bst` in the directory
`tests/format/junctions/override-self` gives the following output:

```
20:17:48 --:--:--              main:core activity                  START   Loading elements
20:17:48 00:00:00              main:core activity                  FAILURE Loading elements

project.conf [line 6 column 2]: Circular reference while searching for 'subproject.bst:self-junction.bst'

    Already searching for 'subproject.bst:self-junction.bst' at: nested-link.bst [line 4 column 10]
```
This commit load ensures the toplevel project is always loaded, even
when addressing subproject elements via link.

Commit cff58ec added a call to `Project.ensure_fully_loaded` to ensure
the toplevel project is resolved first when addressing subproject
elements on the command line. The commit assumes that whenever
subproject elements are referenced on the command line,
`Loader.get_loader` is called with `provenance_node == None`.

However, if a link element that points to a subproject element is
referenced on the command line then `get_loader` will be called with
`provenance_node` referencing the link element. This means that
`get_loader` skips the call to `ensure_fully_loaded` causing buildstream
to crash.

This commit fixes the crash by moving the call to `ensure_fully_loaded`
up the call chain into `Loader.load` where we know that the element is
addressed from the command line.
This commit moves subproject into a new intermediate project and the
subproject.bst junction element is replaced by a link element. Including
a file from a nested junction via a link element in the top level
project.conf file tests more code paths in the loader.

This change shows a bug in the loader, running `bst show --deps none
target.bst` in the directory `tests/format/junctions/include-complex`
gives the following output:

```
20:02:32 --:--:--              main:core activity                  START   Loading elements
20:02:32 00:00:00              main:core activity                  FAILURE Loading elements

intermediate-project.bst:project.conf [line 5 column 2]: Circular reference while searching for 'subproject.bst'

    Already searching for 'subproject.bst' at: subproject.bst [line 4 column 10]
```
Comment thread tests/format/junctions.py
"target",
["target.bst", "subproject.bst:target.bst"],
["target.bst", "subproject.bst:target.bst", "intermediate-project.bst:subproject.bst:target.bst"],
ids=["toplevel-target", "subproject-target"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New ID is missing, blocking pytest.

Suggested change
ids=["toplevel-target", "subproject-target"],
ids=["toplevel-target", "subproject-target", "nested-link-target"],

# Other callers of `_parse_name` or `_load_file` that reference
# files through a project element or otherwise do not need to
# ensure fully loaded.
self.project.ensure_fully_loaded()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this loading is too eager, resulting in a regression of #1686.

I'm trying to find an alternative fix that avoids that regression.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #2114, which fixes this issue in a different way. It includes and passes your tests from this branch (adjusted to keep the previous tests without changes).

@juergbi
Copy link
Copy Markdown
Contributor

juergbi commented Apr 30, 2026

Closing this as #2114 has been merged to address the issue.

@juergbi juergbi closed this Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bst build command fails intermittently

2 participants